package yrl.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class AreaRunnable implements Runnable {
	private Socket client;

	public AreaRunnable(Socket client) {
		this.client = client;
	}

	@Override
	public void run() {
		DataInputStream inputStreamFromClient;
		try {
			inputStreamFromClient = new DataInputStream(client.getInputStream());
			DataOutputStream outputStreamToClient = new DataOutputStream(client.getOutputStream());
			while (true) {
				double radius = inputStreamFromClient.readDouble();
				double area = radius * radius * Math.PI;
				System.out.println("服务器：接收到客户端半径：" + radius);
				System.out.println("服务器端：计算面积为：" + area);
				outputStreamToClient.writeDouble(area);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
